'''This module allows you to 'roam' away from your pc, and let it 
automatically set you to being away. It allows you to set the timeout from 
your last text and the away message.'''
############################################################################
#    Copyright (C) 2006 by Robert Small                                    #
#    SmallR2002@Gmail.com                                                  #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

__module_name__        = "bcroam"
__module_version__     = "0.0.2"
__module_description__ = "This module allows you to 'roam' away from your pc, and let it automatically set you to being away. It allows you to set the timeout from your last text and the away message."

import xchat
import sys
import time
import os

if (sys.path.count(os.path.dirname(__file__) ) == 0):
    sys.path.append(os.path.dirname(__file__) )

#  Pretty much essential.
import bcsettings
import bcmisc

def msg_timer(word, word_eol, userdata): #IGNORE:W0613
    '''
    Automatically returns you when you say something and resets your timer when you speak.
    @param word: all the data you need to work with, chopped up into small parts.
    @type word: string
    @param word_eol: all the data you need to work with, chopped from wherever you're starting from.
    @type word_eol: string
    @param userdata: custom object to pass back.
    @type userdata: object
    '''
    bcmisc.last_commands_time = time.time()
    if (bcsettings.auto_return == True and xchat.get_info("away")):
        if (bcsettings.auto_return_global == True):
            xchat.command('allserv back')
        else:
            xchat.command('back')
            
    
    return xchat.EAT_NONE
#End of sub

def away_check(word, word_eol, userdata):  #IGNORE:W0613
    '''
    Checks if you're away, triggered by others speaking, sets you to away when it detects that you are.
    @param word: all the data you need to work with, chopped up into small parts.
    @type word: string
    @param word_eol: all the data you need to work with, chopped from wherever you're starting from.
    @type word_eol: string
    @param userdata: custom object to pass back.
    @type userdata: object
    '''
    if (time.time() > (bcmisc.last_commands_time + bcsettings.last_commands_time_out)) and (xchat.get_info("away") is None):
        xchat.command('allserv away ' + bcsettings.auto_away_message)
    